#include"progress.h"
#include<unistd.h>
#define N 101
#define flag '#'
void shouwprogressbar()
{
    char buffer[N]={0};
    int index =0;
    char * str="|/-\\";
    int len =strlen(str);
    while(index<101)
    {
        printf("\033[0;32m[%-100s]\033[1;31m[%d%%]\033[0;36m[%c]\033[0m\r",buffer,index,str[index%len]);
        fflush(stdout);
        buffer[index++]=flag;
        usleep(50000);
    }
    printf("\n");
}


void filueshprocessbar(double total,double cur)
{
    char buffer[N]={0};
   static  int index =0;//用来维持cur不改变但是仍在加载的情况
    char * str="|/-\\";
    int len =strlen(str);
    double rate =cur/total;
    int num =(int)(rate*100);
    for(int i=0;i<num;i++)
    {
        buffer[i] =flag;
    }
    printf("\033[0;32m[%-100s]\033[1;31m[%.1lf%%]\033[0;36m[%c]\033[0m\r",buffer,rate*100,str[index%len]);
    fflush(stdout);
    index++;
}
